public class MyCircularDeque {
    //采用数组的形式模拟双端队列
    private int[] nums;
    //定义一个容器里面元素大小
    private int currentCount;
    /** Initialize your data structure here. Set the size of the deque to be k. */
    public MyCircularDeque(int k) {
        this.nums = new int[k];
        currentCount = 0;
    }


    /** Adds an item at the front of Deque. Return true if the operation is successful. */
    public boolean insertFront(int value) {
        //如果数组已经满了，returnfalse
        boolean full = this.isFull();
        if(full){
            return false;
        }else{
            //如果数组没满，将原来的数组移动
            for(int i =currentCount;i>=1;i--){
                nums[i] = nums[i-1];
            }
            nums[0] = value;
            currentCount++;
            return true;
        }
    }

    /** Adds an item at the rear of Deque. Return true if the operation is successful. */
    public boolean insertLast(int value) {
        boolean full = this.isFull();
        if(full){
            return false;
        }else{
            nums[currentCount] = value;
            currentCount++;
            return true;
        }
    }

    /** Deletes an item from the front of Deque. Return true if the operation is successful. */
    public boolean deleteFront() {
        boolean empty = this.isEmpty();
        if(empty){
            return false;
        }else{
            //遍历数组
            for(int i=0;i<currentCount-1;i++){
                nums[i] = nums[i+1];
            }
            nums[currentCount-1] =0;
            currentCount--;
            return true;
        }
    }

    /** Deletes an item from the rear of Deque. Return true if the operation is successful. */
    public boolean deleteLast() {
        boolean empty = this.isEmpty();
        if(empty){
            return false;
        }else{
            nums[currentCount-1] = 0;
            currentCount--;
            return true;
        }
    }

    /** Get the front item from the deque. */
    public int getFront() {
        boolean empty = this.isEmpty();
        if(empty){
            return -1;
        }else{
            return nums[0];
        }
    }

    /** Get the last item from the deque. */
    public int getRear() {
        boolean empty = this.isEmpty();
        if(empty){
            return -1;
        }else{
            return nums[currentCount-1];
        }
    }

    /** Checks whether the circular deque is empty or not. */
    public boolean isEmpty() {
        return currentCount==0?true:false;
    }

    /** Checks whether the circular deque is full or not. */
    public boolean isFull() {
        return currentCount>=nums.length?true:false;
    }
}
